Stable-diffusion-xl-base-1.0¶

MODELEX-2.png

API request for the stable-diffusion-xl-base-1.0¶

In [7]:
import requests

API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
headers = {"Authorization": "Bearer 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"}

Generation of image with the promp : Astronaut riding a horse¶

In [8]:
def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.content
image_bytes = query({
	"inputs": "Astronaut riding a horse",
})
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))
image
Out[8]:

Generation of image with the promp : Garfield on the moon¶

In [9]:
def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.content
image_bytes = query({
	"inputs": "Garfield on the moon",
})
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))
image
Out[9]:

Generation of image with the promp : Peace and love¶

In [10]:
def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.content
image_bytes = query({
	"inputs": "Peace and love",
})
import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))
image
Out[10]:
In [ ]: